<template>
  <view class="wrapper">
    <list :list="list" />
  </view>
</template>

<script>
import List from '../../components/list/index'
import base64 from '../../util/base64'
import Product from '../../api/product'
const productModel = new Product()
export default {
  components: {
    List
  },
  data() {
    return {
      list: [],
      queryList: {
        page: 0,
        pageSize: 10,
        busy: false
      },
    }
  },
  onLoad() {
    this.getList()
  },
  onReachBottom() {
    this.getList(true)
  },
  methods: {
    getList(append = false) {
      if (this.queryList.busy === false) {
        this.queryList.page++
        this.loading = true
        this.queryList.busy = true
        productModel.productList({
          ...this.queryList,
        }).then(response => {
          let { data } = response
          data = base64.parse(data)
          if (data.list.length === 0) {
            this.queryList.busy = true
          } else {
            this.queryList.busy = false
            if (append) {
              this.list = this.list.concat(data.list)
            } else {
              this.list = data.list
            }
          }
        })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.wrapper {
  background: $background_color;
  padding: 20rpx;
}
</style>
